home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / TextUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  11.7 KB  |  414 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        TextUtils.h
  3.  
  4.      Contains:    Text Utilities Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1985-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __TEXTUTILS__
  18. #define __TEXTUTILS__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24. #ifndef __NUMBERFORMATTING__
  25.     #include <NumberFormatting.h>
  26. #endif
  27.  
  28. #ifndef __STRINGCOMPARE__
  29.     #include <StringCompare.h>
  30. #endif
  31.  
  32. #ifndef __DATETIMEUTILS__
  33.     #include <DateTimeUtils.h>
  34. #endif
  35.  
  36.  
  37.  
  38.  
  39. #if PRAGMA_ONCE
  40. #pragma once
  41. #endif
  42.  
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46.  
  47. #if PRAGMA_IMPORT
  48. #pragma import on
  49. #endif
  50.  
  51. #if PRAGMA_STRUCT_ALIGN
  52.     #pragma options align=mac68k
  53. #elif PRAGMA_STRUCT_PACKPUSH
  54.     #pragma pack(push, 2)
  55. #elif PRAGMA_STRUCT_PACK
  56.     #pragma pack(2)
  57. #endif
  58.  
  59. /*
  60.  
  61.     Here are the current System 7 routine names and the translations to the older forms.
  62.     Please use the newer forms in all new code and migrate the older names out of existing
  63.     code as maintainance permits.
  64.     
  65.     NEW NAME                    OLD NAMEs                    OBSOLETE FORM (no script code)
  66.  
  67.     FindScriptRun
  68.     FindWordBreaks                                            NFindWord, FindWord
  69.     GetIndString            
  70.     GetString
  71.     Munger
  72.     NewString                
  73.     SetString                
  74.     StyledLineBreak
  75.     TruncString
  76.     TruncText
  77.  
  78.     UpperString ($A054)            UprString, UprText
  79.     UppercaseText                SCUpperText (a only)        UpperText ($A456)
  80.     LowercaseText                                            LwrString, LowerText, LwrText ($A056)
  81.     StripDiacritics                                            StripText ($A256)
  82.     UppercaseStripDiacritics                                StripUpperText ($A656)
  83.  
  84.  
  85. */
  86.  
  87. /* Type for truncWhere parameter in TruncString, TruncText */
  88. typedef short                             TruncCode;
  89. enum {
  90.                                                                 /* Constants for truncWhere argument in TruncString and TruncText */
  91.     truncEnd                    = 0,                            /* Truncate at end */
  92.     truncMiddle                    = 0x4000,                        /* Truncate in middle */
  93.     smTruncEnd                    = 0,                            /* Truncate at end - obsolete */
  94.     smTruncMiddle                = 0x4000                        /* Truncate in middle - obsolete */
  95. };
  96.  
  97. enum {
  98.                                                                 /* Constants for TruncString and TruncText results */
  99.     notTruncated                = 0,                            /* No truncation was necessary */
  100.     truncated                    = 1,                            /* Truncation performed */
  101.     truncErr                    = -1,                            /* General error */
  102.     smNotTruncated                = 0,                            /* No truncation was necessary - obsolete */
  103.     smTruncated                    = 1,                            /* Truncation performed    - obsolete */
  104.     smTruncErr                    = -1                            /* General error - obsolete */
  105. };
  106.  
  107. typedef SInt8                             StyledLineBreakCode;
  108. enum {
  109.     smBreakWord                    = 0,
  110.     smBreakChar                    = 1,
  111.     smBreakOverflow                = 2
  112. };
  113.  
  114.  
  115. struct ScriptRunStatus {
  116.     SInt8                             script;
  117.     SInt8                             runVariant;
  118. };
  119. typedef struct ScriptRunStatus            ScriptRunStatus;
  120.  
  121. struct BreakTable {
  122.     char                             charTypes[256];
  123.     short                             tripleLength;
  124.     short                             triples[1];
  125. };
  126. typedef struct BreakTable                BreakTable;
  127. typedef BreakTable *                    BreakTablePtr;
  128.  
  129. struct NBreakTable {
  130.     SInt8                             flags1;
  131.     SInt8                             flags2;
  132.     short                             version;
  133.     short                             classTableOff;
  134.     short                             auxCTableOff;
  135.     short                             backwdTableOff;
  136.     short                             forwdTableOff;
  137.     short                             doBackup;
  138.     short                             length;                        /* length of NBreakTable */
  139.     char                             charTypes[256];
  140.     short                             tables[1];
  141. };
  142. typedef struct NBreakTable                NBreakTable;
  143. typedef NBreakTable *                    NBreakTablePtr;
  144. /* The following functions are new names that work on 68k and PowerPC*/
  145. EXTERN_API( long )
  146. Munger                            (Handle                 h,
  147.                                  long                     offset,
  148.                                  const void *            ptr1,
  149.                                  long                     len1,
  150.                                  const void *            ptr2,
  151.                                  long                     len2)                                ONEWORDINLINE(0xA9E0);
  152.  
  153. EXTERN_API( StringHandle )
  154. NewString                        (ConstStr255Param         theString)                            ONEWORDINLINE(0xA906);
  155.  
  156. EXTERN_API( void )
  157. SetString                        (StringHandle             theString,
  158.                                  ConstStr255Param         strNew)                                ONEWORDINLINE(0xA907);
  159.  
  160. EXTERN_API( StringHandle )
  161. GetString                        (short                     stringID)                            ONEWORDINLINE(0xA9BA);
  162.  
  163. EXTERN_API( void )
  164. GetIndString                    (Str255                 theString,
  165.                                  short                     strListID,
  166.                                  short                     index);
  167.  
  168. EXTERN_API_C( void )
  169. setstring                        (StringHandle             theString,
  170.                                  const char *            strNew);
  171.  
  172. EXTERN_API_C( StringHandle )
  173. newstring                        (const char *            theString);
  174.  
  175. EXTERN_API_C( void )
  176. getindstring                    (char *                    theString,
  177.                                  short                     strListID,
  178.                                  short                     index);
  179.  
  180. EXTERN_API( StyledLineBreakCode )
  181. StyledLineBreak                    (Ptr                     textPtr,
  182.                                  long                     textLen,
  183.                                  long                     textStart,
  184.                                  long                     textEnd,
  185.                                  long                     flags,
  186.                                  Fixed *                textWidth,
  187.                                  long *                    textOffset)                            FOURWORDINLINE(0x2F3C, 0x821C, 0xFFFE, 0xA8B5);
  188.  
  189. EXTERN_API( short )
  190. TruncString                        (short                     width,
  191.                                  Str255                 theString,
  192.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x8208, 0xFFE0, 0xA8B5);
  193.  
  194. EXTERN_API( short )
  195. TruncText                        (short                     width,
  196.                                  Ptr                     textPtr,
  197.                                  short *                length,
  198.                                  TruncCode                 truncWhere)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFDE, 0xA8B5);
  199.  
  200. EXTERN_API( void )
  201. FindWordBreaks                    (Ptr                     textPtr,
  202.                                  short                     textLength,
  203.                                  short                     offset,
  204.                                  Boolean                 leadingEdge,
  205.                                  BreakTablePtr             breaks,
  206.                                  OffsetTable             offsets,
  207.                                  ScriptCode             script)                                FOURWORDINLINE(0x2F3C, 0xC012, 0x001A, 0xA8B5);
  208.  
  209. EXTERN_API( void )
  210. LowercaseText                    (Ptr                     textPtr,
  211.                                  short                     len,
  212.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0000, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  213.  
  214. EXTERN_API( void )
  215. UppercaseText                    (Ptr                     textPtr,
  216.                                  short                     len,
  217.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0400, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  218.  
  219. EXTERN_API( void )
  220. StripDiacritics                    (Ptr                     textPtr,
  221.                                  short                     len,
  222.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0200, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  223.  
  224. EXTERN_API( void )
  225. UppercaseStripDiacritics        (Ptr                     textPtr,
  226.                                  short                     len,
  227.                                  ScriptCode             script)                                SIXWORDINLINE(0x3F3C, 0x0600, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  228.  
  229. EXTERN_API( ScriptRunStatus )
  230. FindScriptRun                    (Ptr                     textPtr,
  231.                                  long                     textLen,
  232.                                  long *                    lenUsed)                            FOURWORDINLINE(0x2F3C, 0x820C, 0x0026, 0xA8B5);
  233.  
  234. #if CALL_NOT_IN_CARBON
  235. /*
  236.       The following functions are old names, but are required for PowerPC builds
  237.       because InterfaceLib exports these names, instead of the new ones.
  238. */
  239. EXTERN_API( void )
  240. FindWord                        (Ptr                     textPtr,
  241.                                  short                     textLength,
  242.                                  short                     offset,
  243.                                  Boolean                 leadingEdge,
  244.                                  BreakTablePtr             breaks,
  245.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0x001A, 0xA8B5);
  246.  
  247. EXTERN_API( void )
  248. NFindWord                        (Ptr                     textPtr,
  249.                                  short                     textLength,
  250.                                  short                     offset,
  251.                                  Boolean                 leadingEdge,
  252.                                  NBreakTablePtr         nbreaks,
  253.                                  OffsetTable             offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0xFFE2, 0xA8B5);
  254.  
  255. /*
  256.    On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  257.    return an error code in register D0, but System 7 PowerMacs do not emulate
  258.    this properly, so checking D0 is unreliable.
  259. */
  260.  
  261.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  262.                                                                                             #pragma parameter LwrText(__A0, __D0)
  263.                                                                                             #endif
  264. EXTERN_API( void )
  265. LwrText                            (Ptr                     textPtr,
  266.                                  short                     len)                                ONEWORDINLINE(0xA056);
  267.  
  268.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  269.                                                                                             #pragma parameter LowerText(__A0, __D0)
  270.                                                                                             #endif
  271. EXTERN_API( void )
  272. LowerText                        (Ptr                     textPtr,
  273.                                  short                     len)                                ONEWORDINLINE(0xA056);
  274.  
  275.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  276.                                                                                             #pragma parameter StripText(__A0, __D0)
  277.                                                                                             #endif
  278. EXTERN_API( void )
  279. StripText                        (Ptr                     textPtr,
  280.                                  short                     len)                                ONEWORDINLINE(0xA256);
  281.  
  282.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  283.                                                                                             #pragma parameter UpperText(__A0, __D0)
  284.                                                                                             #endif
  285. EXTERN_API( void )
  286. UpperText                        (Ptr                     textPtr,
  287.                                  short                     len)                                ONEWORDINLINE(0xA456);
  288.  
  289.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  290.                                                                                             #pragma parameter StripUpperText(__A0, __D0)
  291.                                                                                             #endif
  292. EXTERN_API( void )
  293. StripUpperText                    (Ptr                     textPtr,
  294.                                  short                     len)                                ONEWORDINLINE(0xA656);
  295.  
  296. #endif  /* CALL_NOT_IN_CARBON */
  297.  
  298. /* The following are new names which are exported by InterfaceLib*/
  299. EXTERN_API( void )
  300. UpperString                        (Str255                 theString,
  301.                                  Boolean                 diacSensitive);
  302.  
  303. EXTERN_API_C( void )
  304. upperstring                        (char *                    theString,
  305.                                  Boolean                 diacSensitive);
  306.  
  307. /* The following are macros which map old names to the names exported by InterfaceLib*/
  308. #if OLDROUTINENAMES
  309. #define UprString(theString, diacSensitive)  \
  310.          UpperString(theString, diacSensitive)
  311. #endif  /* OLDROUTINENAMES */
  312.  
  313. /* Old routine name but no new names are mapped to it:*/
  314. #if CALL_NOT_IN_CARBON
  315.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  316.                                                                                             #pragma parameter UprText(__A0, __D0)
  317.                                                                                             #endif
  318. EXTERN_API( void )
  319. UprText                            (Ptr                     textPtr,
  320.                                  short                     len)                                ONEWORDINLINE(0xA054);
  321.  
  322. #endif  /* CALL_NOT_IN_CARBON */
  323.  
  324. /*
  325.     Functions for converting between C and Pascal Strings
  326.     (Previously in Strings.h)
  327.     
  328.     Note: CopyPascalStringToC, CopyCStringToPascal, c2pstrcpy, and p2cstrcpy
  329.           are written to allow inplace conversion.  That is, the src and dst
  330.           parameters can point to the memory location.  
  331.           
  332.     Note: c2pstr, C2PStr, p2cstr, and P2CStr are all deprecated.  These functions
  333.           only do inplace conversion and often require casts to call them.  This can
  334.           cause bugs because you can easily cast away a const and change the 
  335.           contents of a read-only buffer.  Do you know what c2pstr("Hello") will do?
  336.     
  337. */
  338. EXTERN_API_C( void )
  339. c2pstrcpy                        (Str255                 dst,
  340.                                  const char *            src);
  341.  
  342. EXTERN_API_C( void )
  343. p2cstrcpy                        (char *                    dst,
  344.                                  ConstStr255Param         src);
  345.  
  346. EXTERN_API_C( void )
  347. CopyPascalStringToC                (ConstStr255Param         src,
  348.                                  char *                    dst);
  349.  
  350. EXTERN_API_C( void )
  351. CopyCStringToPascal                (const char *            src,
  352.                                  Str255                 dst);
  353.  
  354. #if CALL_NOT_IN_CARBON
  355. EXTERN_API_C( StringPtr )
  356. c2pstr                            (char *                    aStr);
  357.  
  358. EXTERN_API( StringPtr )
  359. C2PStr                            (Ptr                     cString);
  360.  
  361. EXTERN_API_C( char *)
  362. p2cstr                            (StringPtr                 aStr);
  363.  
  364. EXTERN_API( Ptr )
  365. P2CStr                            (StringPtr                 pString);
  366.  
  367. #endif  /* CALL_NOT_IN_CARBON */
  368.  
  369. #if !TARGET_OS_MAC
  370.     /* Added for QuickTime 3.0 */
  371.     #define C2PStr(a)  (StringPtr)c2pstr((Ptr)(a))
  372.     #define P2CStr(a)  (Ptr)p2cstr(a)
  373.  
  374.     #define CopyPascalStringToC(src,dst) p2cstrcpy(dst,src)
  375.     #define CopyCStringToPascal(src,dst) c2pstrcpy(dst,src)
  376. #endif
  377. /*
  378.    Added macros to convert p2cstr and c2pstr calls into p2cstrcpy and c2pstrcpy calls,
  379.    and map C2PStr and P2CStr to c2pstr and p2cstr for Carbon.
  380.    The use of the often unappreciated comma operator to coerce the proper return values,
  381.    since the p2cstrcpy and c2pstrcpy routines have no return value.
  382. */
  383.  
  384. #if TARGET_OS_MAC && TARGET_API_MAC_CARBON && OLDP2C
  385.     #define p2cstr(aStr) (p2cstrcpy((char *) aStr, aStr) , (char *) aStr)
  386.     #define c2pstr(aStr) (c2pstrcpy(aStr, (char *) aStr) , (StringPtr) aStr)
  387.  
  388.     #define C2PStr(a)  (StringPtr)c2pstr((Ptr)(a))
  389.     #define P2CStr(a)  (Ptr)p2cstr(a)
  390. #endif
  391.  
  392.  
  393.  
  394. #if PRAGMA_STRUCT_ALIGN
  395.     #pragma options align=reset
  396. #elif PRAGMA_STRUCT_PACKPUSH
  397.     #pragma pack(pop)
  398. #elif PRAGMA_STRUCT_PACK
  399.     #pragma pack()
  400. #endif
  401.  
  402. #ifdef PRAGMA_IMPORT_OFF
  403. #pragma import off
  404. #elif PRAGMA_IMPORT
  405. #pragma import reset
  406. #endif
  407.  
  408. #ifdef __cplusplus
  409. }
  410. #endif
  411.  
  412. #endif /* __TEXTUTILS__ */
  413.  
  414.